from pandas import read_csv
from datetime import datetime
from pandas import concat
from pandas import DataFrame
def parse(x):
    return datetime.strptime((x,'%Y %m %d %H'))
#将天气中不需要的数据去除，并重新保存
dateset_temp_weather=read_csv('附件3-气象数据.csv',encoding='gbk')
dateset_temp_weather=dateset_temp_weather[366:]
dateset_temp_weather.drop_duplicates(inplace=True)      #天气数据中有重复数据，去重
dateset_temp_weather.drop(index=[1125],inplace=True)     #用电数据中没有2021年1月26日
dateset_temp_weather.to_csv('NewWeather.csv',index=False)
dataset_temp_weather2=dateset_temp_weather[282:]
dataset_temp_weather2.to_csv('NewWeather2.csv',index=False)
#将各行业用电分成不同表
dataset_Epower=read_csv('附件2-行业日负荷数据-date.csv', encoding='gbk')
dataset_Epower.drop(columns=['行业类型'],inplace=True)  #将行业类型去掉
dataset_big=dataset_Epower[0:973]
dataset_big.to_csv('Classfication/big.csv',index=False)
dataset_nonsimple=dataset_Epower[973:1664]
dataset_nonsimple.to_csv('Classfication/nonsimple.csv',index=False)
dataset_simple=dataset_Epower[1664:2637]
dataset_simple.to_csv('Classfication/simple.csv',index=False)
dataset_business=dataset_Epower[2637:]
dataset_business.to_csv('Classfication/business.csv',index=False)
#将各行业用电和天气表链接
dataset_weather=read_csv('NewWeather.csv')
print(dataset_weather)
dataset_weather_non=read_csv('NewWeather2.csv')
dataset_big=read_csv('Classfication/big.csv')
dataset_nonsimple=read_csv('Classfication/nonsimple.csv')
dataset_simple=read_csv('Classfication/simple.csv')
dataset_business=read_csv('Classfication/business.csv')

#将天气中的日期信息丢弃
dataset_weather.drop(columns=['日期'],inplace=True)
# #用天气和各个行业用电表单合并
dataset_big=concat([dataset_big,dataset_weather],axis=1)   #将大工业用电数据和天气数据进行合并
# dataset_big.dropna(inplace=True)
dataset_big.to_csv('WithWeather/BigIndustry.csv',index=False)
# dataset_nonsimple=concat([dataset_nonsimple,dateset_weather.drop([0,282],inplace=False)],axis=1)  #将非普通工业用电和天气数据进行合并
dataset_simple=concat([dataset_simple,dataset_weather],axis=1)   #将普通工业用电数据和天气数据进行合并
# dataset_simple.dropna(inplace=True)          #去掉Nan行
dataset_simple.to_csv('WithWeather/SimpleIndustry.csv',index=False)    #将普通工业用电的数据保存
dataset_business=concat([dataset_business,dataset_weather],axis=1)  #将商业用电和天气数据进行合并
# dataset_business.dropna(inplace=True)
dataset_business.to_csv('WithWeather/Business.csv',index=False)   #将商业用电保存
# print(dataset_simple)
dataset_nonsimple=concat([dataset_nonsimple,dataset_weather_non],axis=1)
# dataset_nonsimple.dropna(inplace=True)
dataset_nonsimple.to_csv('WithWeather/NonSimple.csv',index=False)
